package chunmap.orm.mapping.type;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import chunmap.util.ChunDaoException;

public class DoubleType  implements DataType {
	@Override
	public String toString() {
		return "double precision";
	}

	@Override
	public void setPreparedStatement(PreparedStatement ps, int parameterIndex,
			Object obj) {
		try {
			if(obj==null){
				ps.setNull(parameterIndex, java.sql.Types.DOUBLE);
				return;
			}
			Double value = (Double) obj;
			ps.setDouble(parameterIndex, value.doubleValue());

		} catch (SQLException e) {
			throw new ChunDaoException(e);
		}
	}

	@Override
	public Object readData(ResultSet rs, int parameterIndex) {
		try {
			double i= rs.getDouble(parameterIndex);
			//if(rs.wasNull())return null;
			return new Double(i);
		} catch (SQLException e) {
			throw new ChunDaoException(e);
		}
	}

}
